/*
 * led.h
 *
 *  Created on: 03.11.2011
 *      Author: g.kruglov
 */

#ifndef LED_H_
#define LED_H_

#include <avr/io.h>
#include <delay_util.h>

#define LED_PORT        PORTC
#define LED_DDR         DDRC
#define BLUELED_P       (1<<PC5)
#define REDLED_P        (1<<PC6)

class Led_t {
private:
    uint16_t BlueTimer;
    bool BlueIsOn, RedIsOn;
public:
    bool BlueNeedToggle, CCidNeedBlink;
    void Init(void)         { LED_DDR |= BLUELED_P | REDLED_P; }
    void Deinit(void)       { RedOff(); BlueOff(); }
    void Task(void)         { if(!BlueIsOn) if(DelayElapsed(&BlueTimer, 205)) BlueOn();}
    void BlueBlink(void)    { BlueOff(); DelayReset(&BlueTimer); }
    void BlueOff(void)      { LED_PORT |=  BLUELED_P; BlueIsOn = false;  }
    void BlueOn(void)       { LED_PORT &= ~BLUELED_P; BlueIsOn = true; }
    void BlueToggle(void)   { LED_PORT ^=  BLUELED_P; BlueIsOn = !BlueIsOn; }
    void RedOff(void)       { LED_PORT |=  REDLED_P; RedIsOn = false;  }
    void RedOn(void)        { LED_PORT &= ~REDLED_P; RedIsOn = true; }
};

extern Led_t Led;


#endif /* LED_H_ */
